﻿using System.Reflection;
using Autofac;
using Autofac.Core;
using PlutoStudio.Configuration.Startup;
using PlutoStudio.Modules;
using PlutoStudio.Domain.UnitOfWork;
using PlutoStudio.Reflection;
using PlutoStudio.Dependency;
using PlutoStudio.Runtime.Caching.Configuration;
using PlutoStudio.Events.Bus;
using PlutoStudio.Runtime.Remoting;
using PlutoStudio.Runtime;
using PlutoStudio.Aspects;
using PlutoStudio.Authorization;
using System;
using System.Collections.Generic;
using System.Linq;
using Castle.Core.Logging;
using PlutoStudio.Localization;
using PlutoStudio.BackgroundJobs;
using PlutoStudio.Resources.Embedded;

namespace PlutoStudio
{
    internal class CoreInstaller : IocInstaller
    {
        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterType<UnitOfWorkDefaultOptions>().As<IUnitOfWorkDefaultOptions>().SingleInstance();
            builder.RegisterType<LocalizationConfiguration>().As<ILocalizationConfiguration>().SingleInstance();
            builder.RegisterType<ModuleManager>().As<IModuleManager>().SingleInstance();
            builder.RegisterType<ModuleConfigurations>().As<IModuleConfigurations>().SingleInstance();
            builder.RegisterType<SettingsConfiguration>().As<ISettingsConfiguration>().SingleInstance();
            builder.RegisterType<ValidationConfiguration>().As<IValidationConfiguration>().SingleInstance();
            builder.RegisterType<StartupConfiguration>().As<IStartupConfiguration>().AsSelf().SingleInstance();
            builder.RegisterType<TypeFinder>().As<ITypeFinder>().SingleInstance();
            builder.RegisterType<AuditingConfiguration>().As<IAuditingConfiguration>().SingleInstance();
             builder.RegisterType<EmbeddedResourcesConfiguration>().As<IEmbeddedResourcesConfiguration>().SingleInstance();
           builder.RegisterType<AssemblyFinder>().As<IAssemblyFinder>().SingleInstance();
            builder.RegisterType<CachingConfiguration>().As<ICachingConfiguration>().SingleInstance();
            builder.RegisterType<AuthorizationConfiguration>().As<IAuthorizationConfiguration>().SingleInstance();
            builder.RegisterType<NavigationConfiguration>().As<INavigationConfiguration>().SingleInstance();
            builder.RegisterType<UnitOfWorkInterceptor>().AsSelf().SingleInstance();
            builder.RegisterType<AuditingInterceptor>().AsSelf().SingleInstance();
            builder.RegisterType<AuthorizationInterceptor>().AsSelf().SingleInstance();
            builder.RegisterType<EventBusConfiguration>().As<IEventBusConfiguration>().SingleInstance();
            builder.RegisterType<LocalizationManager>().AsSelf().As<ILocalizationManager>().SingleInstance();
            builder.RegisterType<BackgroundJobConfiguration>().As<IBackgroundJobConfiguration>().SingleInstance();
        }

        protected override Assembly ThisAssembly => typeof(CoreInstaller).Assembly;


    }
}